﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Douban.Modules.Conversation.ViewModels;

namespace Douban.Modules.Conversation.Views
{
    /// <summary>
    /// CaptchaView.xaml 的交互逻辑
    /// </summary>
    public partial class CaptchaView : ICaptchaView
    {
        public CaptchaView()
        {
            InitializeComponent();
        }

        #region ICaptchaView Members

        public ICaptchaViewModel Context
        {
            get
            {
                return this.DataContext as ICaptchaViewModel;
            }
            set
            {
                this.DataContext = value;
            }
        }

        public void ShowView()
        {
            this.ShowDialog();
        }

        public void CloseView()
        {
            this.Close();
        }

        public BindingExpression GetBindingCaptchaString()
        {
            return CaptchaStringTextBox.GetBindingExpression(TextBox.TextProperty);
        }
        
        public event KeyEventHandler SendCaptchaKeyDown;

        #endregion

        private void CaptchaView_Loaded(object sender, RoutedEventArgs e)
        {
            CaptchaStringTextBox.Focus();
        }

        private void CaptchaStringTextBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (SendCaptchaKeyDown != null)
                SendCaptchaKeyDown(sender, e);
        }
    }
}
